//
//  OrderInforBottomView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/7.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "OrderInforBottomView.h"

@implementation OrderInforBottomView
{
    NSMutableArray *btnArr;
    GLGWLabel *timeLab;
    GLGWLabel *bottomLeftLabel;
}

- (id)initWithFrame:(CGRect)aFrame inSuperView:(UIView *)aSuperView {
    if (self = [super initWithFrame:aFrame inSuperView:aSuperView]) {
        self.backgroundColor = [UIColor whiteColor];
        //
        GLGWView * lineView = [[GLGWView alloc] initWithInSuperView:self];
        lineView.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(self);
            make.height.equalTo(@1);
        }];
        btnArr = [NSMutableArray array];
        NSArray * butTitArr = @[@"再次购买",@"下载合同",@"再次购买",@"下载合同"];
        for (int i=0; i<butTitArr.count; i++) {
            GLGWButton * bottomBut = [[GLGWButton alloc] initWithTitle:butTitArr[i] titleLableFont:SYSTEMFONT(12) titleLableColor:kColor_Rule_Yellow theCornerRadius:kHeightProportion_In_iPhoneTriploid(15) theBorderWidth:1.0 theBorderColor:kColor_Rule_Yellow backgroundColr:[UIColor whiteColor] inSuperView:self];
            [bottomBut mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(15)-kWidthProportion_In_iPhoneTriploid(85)*i);
                make.top.equalTo(self.mas_top).offset(kHeightProportion_In_iPhoneTriploid(12));
                make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(75)));
                make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(30)));
            }];
//            bottomBut.tag = 400+i;
            [bottomBut addTarget:self action:@selector(bottomButAction:) forControlEvents:UIControlEventTouchUpInside];
            [btnArr addObject:bottomBut];
        }
        
        GLGWLabel *timeLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#EC5353"] inSuperView:self];
        timeLabel.text = @"剩余00:30:30";
        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(18));
            make.bottom.equalTo(self.mas_bottom).offset(-kHeightProportion_In_iPhoneTriploid(13));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(17)));
        }];
        timeLabel.hidden = YES;
        timeLab = timeLabel;
        
        GLGWLabel *bottomLeftLab = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(12) theColor:[UIColor colorWithHexString:@"#EC5353"] inSuperView:self];
        bottomLeftLab.text = @"左边的时间"; // 自有经理人下
        [bottomLeftLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(timeLabel.mas_left).offset(-kWidthProportion_In_iPhoneTriploid(20));
            make.bottom.equalTo(timeLabel.mas_bottom);
            make.height.equalTo(timeLabel.mas_height);
        }];
        bottomLeftLab.hidden = YES;
        bottomLeftLabel = bottomLeftLab;
    }
    return self;
}

- (void)bottomButAction:(GLGWButton *)sender {
    if (self.Block_BottomAction) {
        self.Block_BottomAction(sender);
    }
}

- (void)setDetailModel:(OrderInfomationDetailDataInfoModel *)detailModel
{
    _detailModel = detailModel;
    // 1：确认中(卖家：待您确认，买家/自由经理人：卖家确认中)2：待支付；3：线下支付待确认；4：待商家发货；5：待收货；6：交易完成；18：支付超时；19：订单取消
    NSInteger cout = 340;
    
    for (int i = 0; i < btnArr.count; i ++) {
        GLGWButton *btn = btnArr[i];
        btn.tag = cout;
        switch (detailModel.orderStatus) {
            case 1:
                if (i == 3) {
                    btn.hidden = YES;
                } else if (i == 2) {
                    [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                } else if (i == 1) {
                    [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                } else if (i == 0) {
                    [self btnStatus:btn titleStr:@"取消并撤回" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 2];
                }
                break;
            case 2:
                if (i == 3) {
                    self.height += 22;
                    self.y -= 22;
                    if (self.accountType == AccountType_FreeManagers) { // 有分享也有时间
                        bottomLeftLabel.hidden = NO;
                        timeLab.hidden = NO;
                        bottomLeftLabel.text = @"剩余00:30:30";
                        timeLab.text = @"分享给客户";
                        [self btnStatus:btn titleStr:@"更多" textColor:@"#666666" layerColor:@"#FFFFFF" tag:cout + 8];
                    } else {
                        timeLab.hidden = NO;
                        timeLab.text = @"剩余00:30:30";
                        [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                    }
                } else if (i == 2) {
                    [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                    
                } else if (i == 1) {
                    if (self.accountType == AccountType_FreeManagers) {
                        [self btnStatus:btn titleStr:@"去支付" textColor:@"#EC5353" layerColor:@"#EC5353" tag:cout + 4];
                    } else {
                        [self btnStatus:btn titleStr:@"取消订单" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 3];
                    }
                    
                } else if (i == 0) {
                    if (self.accountType == AccountType_FreeManagers) {
                        [self btnStatus:btn titleStr:@"去支付" textColor:@"#EC5353" layerColor:@"#EC5353" tag:cout + 9];
                    } else {
                        [self btnStatus:btn titleStr:@"去支付" textColor:@"#EC5353" layerColor:@"#EC5353" tag:cout + 4];
                    }
                }
                break;
            case 3:
                if (i == 3) {
                    btn.hidden = YES;
                } else if (i == 2) {
                    btn.hidden = YES;
                } else if (i == 1) {
                    [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                } else if (i == 0) {
                    [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                }
                break;
            case 4:
                if (i == 3) {
                    btn.hidden = YES;
                } else if (i == 2) {
                    [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                } else if (i == 1) {
                    [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                } else if (i == 0) {
                    [self btnStatus:btn titleStr:@"取消并撤回" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 2];
                }
                break;
            case 5: // 这个需要判断是否有提货单
                if (detailModel.receivingGoodsType == 1) {
                    if (i == 3) {
                        btn.hidden = YES;
                    } else if (i == 2) {
                        [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                    } else if (i == 1) {
                        [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                    } else if (i == 0) {
                        [self btnStatus:btn titleStr:@"确认收货" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 5];
                    }
                } else {
                    if (i == 3) { // 这里是有提货单的
                        [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                    } else if (i == 2) {
                        [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                    } else if (i == 1) {
                        [self btnStatus:btn titleStr:@"提货单" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 6];
                    } else if (i == 0) {
                        [self btnStatus:btn titleStr:@"确认收货" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 5];
                    }
                }
                break;
            case 6:
                if (i == 3) {
                    btn.hidden = YES;
                } else if (i == 2) {
                    [self btnStatus:btn titleStr:@"下载合同" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 0];
                } else if (i == 1) {
                    [self btnStatus:btn titleStr:@"申请发票" textColor:@"#666666" layerColor:@"#CCCCCC" tag:cout + 7];
                } else if (i == 0) {
                    [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                }
                break;
            case 18:
                break;
            case 19:
                if (i == 3) {
                    btn.hidden = YES;
                } else if (i == 2) {
                    btn.hidden = YES;
                } else if (i == 1) {
                    btn.hidden = YES;
                } else if (i == 0) {
                    [self btnStatus:btn titleStr:@"再次购买" textColor:@"#A89A60" layerColor:@"#A89A60" tag:cout + 1];
                }
                break;
            default:
                break;
        }
    }
}

- (void)btnStatus:(GLGWButton *)btn titleStr:(NSString *)titleStr textColor:(NSString *)colorStr layerColor:(NSString *)layerColorStr tag:(NSInteger)tag
{
    [btn setTitle:titleStr forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor colorWithHexString:colorStr] forState:UIControlStateNormal];
    btn.layer.borderColor = [UIColor colorWithHexString:layerColorStr].CGColor;
    btn.tag = tag;
    btn.hidden = NO;
}


@end
